package org.fuys.coder.application;

import org.fuys.coder.common.constants.ResultMessageConstants;
import org.fuys.coder.common.entity.Pair;
import org.fuys.coder.common.entity.Result;
import org.fuys.coder.common.exception.BusinessException;
import org.fuys.coder.common.holder.UserHolder;
import org.fuys.coder.domain.act.support.model.req.ActPageGetReq;
import org.fuys.coder.domain.act.support.model.vo.ActVO;
import org.fuys.coder.domain.act.support.service.IActSupportService;
import org.fuys.coder.domain.signup.service.ISignUpService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.application
 * @className: ActivityInfoController
 * @author: WangJing
 * @description: 活动信息 如抽奖具体信息 或者是 签到的天数信息
 * @date: 2024/6/30 17:35
 * @version: 1.0
 */
@RestController
@RequestMapping("/fuyscoder/actInfo")
public class ActivityInfoController {

    @Resource
    private ISignUpService signUpService;

    @Resource
    private IActSupportService actSupportService;

    /**
     * @return Result
     * @author WangJing
     * @description 查看签到情况
     * @date 2024/8/25 17:33
     */
    @GetMapping("/signup")
    public Result signUpInfo(){
        final Integer integer = UserHolder.get();
        if(ObjectUtils.isEmpty(integer)){
            //如果为空 说明没有登录 或者是登录过期了 需要重新请求令牌 这个情况不予受理
            throw new BusinessException("用户信息不完整");
        }
        final Pair<Integer, byte[]> integerPair = signUpService.userSignInfo(integer);
        return Result.ok().data(integerPair);
    }

    /**
     * @param actId: 活动id
     * @return Result
     * @author WangJing
     * @description 获取具体id对应的活动信息
     * @date 2024/8/25 17:34
     */
    @GetMapping("/activity/{actId}")
    public Result getLotteryAct(@PathVariable("actId") Long actId
            , @RequestParam(value = "actType")Integer actType){
        ActVO actVO=null;
        try {
            actVO = actSupportService.getActById(actId,actType);
        } catch (Exception e) {
            return Result.error(ResultMessageConstants.NO_ACT_INFO);
        }
        return Result.ok().data(actVO);
    }

    /**
     * @param :
     * @return Result
     * @author WangJing
     * @description 获取当前页的活动信息 单数获取普通活动 偶数获取抽奖活动
     * @date 2024/8/25 17:34
     */
    @PostMapping("/activity")
    public Result getPageActivity(@RequestBody ActPageGetReq req){
        Pair<List<ActVO>,Long> voList=null;
        try {
            voList = actSupportService.getPageAct(req);
        } catch (Exception e) {
            return Result.error(ResultMessageConstants.NO_ACT_PAGE);
        }
        return Result.ok().data(voList);
    }

    @GetMapping("/activity/cur")
    public Result getCurHotActivity(){
        List<ActVO> actVOList=null;
        try {
            actVOList = actSupportService.getCurHotActivity();
        } catch (Exception e) {
            return Result.error(ResultMessageConstants.NO_ACT_RECOMMEND);
        }
        return Result.ok().data(actVOList);
    }

}
